/**
 * Created by Eric.Dou on 1/6/14.
 */
define({
    views: ['layout'],
    views_layout: {
        html: function (jQuery) {
            var target = '#frame';
            var wrapTarget = jQuery(target);
            // wrapTarget.html("");// clean inner html content.
            //if(!wrapTarget.hasClass('easyui-layout'))
            //{
            wrapTarget.addClass('easyui-layout');
            //}
            var creator = jQuery.element;
            creator.div(
                creator.div(
                creator.div(
                    creator.a(
                    creator.i({className:'icon-leaf'}),
                    ' 校信后台管理系统 ',
                    creator.small('v1.0.0')
                    ).attr({'class':"brand"}),
                    creator.div(
                        {className: 'pull-right'},
                        creator.p(
                            creator.button({className: 'btn btn-default navbar-btn', type: 'button'},
                                creator.span({className: 'glyphicon glyphicon-envelope'})
                            ),
                            creator.button({className: 'btn btn-default navbar-btn', type: 'button'},
                                creator.span({className: 'glyphicon glyphicon-tasks'},
                                    ' Info ',
                                    creator.span({className: 'badge'}, '1')
                                )
                            ),
                            creator.button({className: 'btn btn-default navbar-btn', type: 'button'},
                                creator.span({className: 'glyphicon glyphicon-user'})
                            )
                        )
                    )
                ).attr({'class':'navbar-inner'})).attr({'class':'navbar'})
            ).attr({id: 'top', 'data-Options': "border:false,region:'north'", style: 'height:45px;overflow-y: hidden'}).appendTo(target);
         /*   creator.div(
                'south'
            ).attr({'data-options': "region:'south'"}).appendTo(target);*/
            creator.div().attr({id: 'westMenuDiv', 'data-options': "border:false,region:'west',split:false", style: 'width:200px;'}).appendTo(target);
            creator.div(
                'center'
            ).attr({'data-options': "region:'center',split:true,minWidth:250,maxWidth:800"}).appendTo(target);
        },
        options: {fit: true},
        target: '#frame',
        widgets: 'layout'

    },
    views_content: {
        target: '#content',
        layout: {
            belongTo:function($) {
                $('#frame').layout('panel','center').html('');
                $('#frame').layout('panel','center').append($('#content'));
            }
        },
        html: {
            lazyLoad: {
                lazyLoadContent: '<p>abc Loading....</p>',
                url: '/api/bo/nav',
                data: {needTotal: false},
                method: 'getJSON',
                handle: function ($,data, status) {
                    console.log(data);
                    console.log("=======================>" + status);
                    var menulist = '<ul class="nav nav-list">';
                    $.each(data, function(i, n) {
                        selectedPanelname = n.text;
                        menulist += '<li>'+selectedPanelname+'</li>';
                        menulist += '<ul class="submenu">';
                        $.each(n.children, function(j, o) {
                            menulist += '<li><a id="'+o.id+'" href="#" link="' + o.value + '">    ' + o.text + '    </a></li> ';
                        });
                        menulist += '</ul>';
                    });
                    menulist+='</ul>';
                    $('#frame').layout('panel','center').html(menulist)
                }
            }

        }
    },
    views_menu: {
        target: '#menuBar',
        widgets: "accordion",
        layout: {
            belongTo: '#westMenuDiv'
        },
        html: {       
            sub: [ 
                {
                    tag: 'div',
                    attr: {title: 'Menu 2', 'data-option': 'icon-save', style: 'overflow:auto;padding:10px'},
                    sub: {
                        tag: 'ul',
                        attr: {'class': 'nav bs-sidenav navbar-right'},
                        sub: [
                            {
                                tag: 'li',
                                sub: {
                                    tag: 'a',
                                    attr: {href: 'app3.html', 'class': 'leftMenu'},
                                    content: ' menu 2 '
                                }
                            }
                            ,
                            {
                                tag: 'li',
                                sub: {
                                    tag: 'a',
                                    attr: {href: 'dyc.class.html', 'class': 'leftMenu'},
                                    content: 'class '
                                }
                            },
                            {
                                tag: 'li',
                                sub: {
                                    tag: 'a',
                                    attr: {href: 'dyc.school.html', 'class': 'leftMenu'},
                                    content: 'school '
                                }
                            },
                            {
                                tag: 'li',
                                sub: {
                                    tag: 'a',
                                    attr: {href: 'dyc.teacher.html', 'class': 'leftMenu'},
                                    content: 'teacher '
                                }
                            }
                        ]
                    }
                }
            ]
        },
        options: {
            fit: true,
            width: 180
        },
        listener: function (jQuery) {

            jQuery('li > a.leftMenu').bind('click', function (event) {
                var url = jQuery(this).attr('href');
                var center = jQuery('#frame').layout('panel', 'center');
                center.panel('refresh', url);
                return false;
            })

        }
    }

})
;